/*              Copyright(c) 2008 Dave Sexton              *
 * http://www.codeplex.com/DocProject                      *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms.Design;
using System.Windows.Forms;

namespace DaveSexton.DocToMaml
{
	internal sealed class UIService : IUIService
	{
		#region Public Properties
		public System.Collections.IDictionary Styles
		{
			get
			{
				throw new NotImplementedException();
			}
		}
		#endregion

		#region Private / Protected
		private readonly ProgramForm owner;
		#endregion

		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="UIService" /> class.
		/// </summary>
		public UIService(ProgramForm owner)
		{
			if (owner == null)
				throw new ArgumentNullException("owner");

			this.owner = owner;
		}
		#endregion

		#region Methods
		public bool CanShowComponentEditor(object component)
		{
			return false;
		}

		public System.Windows.Forms.IWin32Window GetDialogOwnerWindow()
		{
			return owner;
		}

		public void SetUIDirty()
		{
			owner.IsDirty = true;
		}

		public bool ShowComponentEditor(object component, System.Windows.Forms.IWin32Window parent)
		{
			throw new NotImplementedException();
		}

		public System.Windows.Forms.DialogResult ShowDialog(System.Windows.Forms.Form form)
		{
			if (form == null)
				throw new ArgumentNullException("form");

			return form.ShowDialog(owner);
		}

		public void ShowError(Exception ex, string message)
		{
			ShowError(ex, message, Resources.Text.GeneralErrorCaption);
		}

		public void ShowError(Exception ex)
		{
			ShowError(ex, null, Resources.Text.GeneralErrorCaption);
		}

		private void ShowError(Exception ex, string message, string caption)
		{
			if (ex == null)
				throw new ArgumentNullException("ex");

			ShowMessage(string.Format(System.Globalization.CultureInfo.CurrentCulture, "{0}{1}: {2}",
				(string.IsNullOrEmpty(message)) ? null : message += Environment.NewLine + Environment.NewLine,
				ex.GetType(), ex.Message), 
				caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
		}

		public void ShowError(string message)
		{
			ShowMessage(message, Resources.Text.GeneralErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
		}

		public void ShowMessage(string message)
		{
			ShowMessage(message, Resources.Text.GeneralMessageCaption, MessageBoxButtons.OK, MessageBoxIcon.None);
		}

		public void ShowMessage(string message, string caption)
		{
			ShowMessage(message, caption, MessageBoxButtons.OK, MessageBoxIcon.None);
		}

		public DialogResult ShowMessage(string message, string caption, MessageBoxButtons buttons)
		{
			return ShowMessage(message, caption, buttons, MessageBoxIcon.None);
		}

		public DialogResult ShowMessage(string message, string caption, MessageBoxButtons buttons, MessageBoxIcon icon)
		{
			return MessageBox.Show(owner, message, caption, buttons, icon, MessageBoxDefaultButton.Button1, owner.MessageBoxOptions);
		}

		public bool ShowToolWindow(Guid toolWindow)
		{
			throw new NotImplementedException();
		}
		#endregion
	}
}
